home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / editor / snmp_0_1.zip / snmp-0.1 / aka / snmp / TypeString.java < prev    next >
Text File  |  1997-06-09  |  2KB  |  108 lines

  1. /*
  2. Snmp Library
  3. Copyright (C) 1997 Alex Kowalenko Associates Pty Ltd. All rights reserved.
  4.  
  5. This software maybe be free distributed, any any form, without fee, 
  6. but may not be modified in any way without express permission of 
  7. the directors of Alex Kowalenko Associates Pty Ltd. 
  8.  
  9. Alex Kowalenko Associates Pty Ltd makes no representations or
  10. warranties about the suitabililty of the software, not even the
  11. implied warranty of merchantability or fitness for any particular
  12. purpose.    
  13. */
  14.  
  15. package aka.snmp;
  16.  
  17. public class TypeString extends Type {
  18.  
  19. /**
  20.  * SNMP STRING type
  21.  * @see Type
  22.  * @version     $Id: TypeString.java,v 1.4 1997/05/18 08:11:54 alex Exp $
  23.  * @author      Alex Kowalenko
  24.  */
  25.  
  26.     static byte asnValue = ASN.OCTET_STR;
  27.     static String name = "STRING";
  28.   
  29.   private String _value;
  30.  
  31. /**
  32.  * Constructor
  33.  */    
  34.  
  35.     TypeString() {
  36.     _value = new String();
  37.     }
  38.  
  39. /**
  40.  * Constructor from string
  41.  */
  42.  
  43.     TypeString(String value) {
  44.     _value = value;
  45.     }
  46.  
  47. /**
  48.  * Constructor from ByteBuffer
  49.  */
  50.  
  51.     TypeString(ByteBuffer buf) {
  52.     int length = ASN.getLength(buf);
  53.     if(length == 0)
  54.         _value = new String();
  55.     else
  56.         _value = buf.toString(length);
  57.     buf.removeBeginning(length);
  58.     return;
  59.     }
  60.  
  61. /**
  62.  * returns name of Type
  63.  */
  64.  
  65.     String typeName() {
  66.     return name;
  67.     };
  68.   
  69. /**
  70.  * Will read a value for the variable from String
  71.  */ 
  72.   
  73.     boolean read(String str) {
  74.     _value = str;
  75.     return true;
  76.     };
  77.  
  78. /**
  79.  * Returns the String value
  80.  */
  81.  
  82.     String value() {
  83.     return _value;
  84.     }
  85.  
  86. /**
  87.  * SNMP protocol conversion.  Convert the variable to a sequence of 
  88.  * bytes, according to SNMP Protocol rules.
  89.  */
  90.  
  91.     public ByteBuffer BERSerialize() {
  92.     ByteBuffer buffer = new ByteBuffer();
  93.     buffer.append(asnValue);
  94.     buffer.append(ASN.buildLength(_value.length()));
  95.     buffer.append(_value);
  96.     return buffer;
  97.     };
  98.  
  99. /**
  100.  * Return a String representation of the type
  101.  */
  102.  
  103.   public String toString() {
  104.       return _value;
  105.   };
  106.  
  107. };
  108.